<template>
  <div style="height: 100%;">
    <Table
      class="monitor-table"
      :columns="colData"
      :data="showTableData"
      :height="tableHeight"
      highlight-row
      @on-current-change="handleRowChange"
      @on-row-dblclick="handleTableClick"
    ></Table>
    <Modal
      class="table-detail-xxx"
      class-name="vertical-center-modal"
      v-model="isShowModal"
      width="1080"
    >
      <p slot="header" style="height:50px;line-height:50px;font-size:36px;">
        <span>{{eventDetailTitle}}</span>
      </p>
      <div style="height: 100%;">
        <img :src="eventDetailData.http_url_image" width="100%" height="100%" />
      </div>
      <div slot="footer">
        <Button type="primary" v-if="isShowVideoPlay" @click="playVideo">查看视频</Button>
      </div>
    </Modal>
    <Modal
      v-model="isShowVideo"
      :title="videoTitle"
      width="1080"
      class-name="vertical-center-modal"
      footer-hide
      @on-cancel="cancelModal(videoIndex)"
    >
      <div style="height: 100%;padding: 10px 10px;">
        <MyVideoMp4 ref="VideoMp4" :src="eventDetailData.http_url_video" v-if="isShowVideo"></MyVideoMp4>
      </div>
    </Modal>
  </div>
</template>

<script>
import MyVideoMp4 from "@/components/myvideo/MyVideoMp4";
export default {
  name: "eventsTable",
  components: {
    MyVideoMp4,
  },
  props: {
    tableData: {
      type: Array
    },
    tableHeight: {
      type: String,
      default: "300"
    }
  },
  data() {
    return {
      // 弹出 对话框 显示事件详情
      eventDetailData: {},
      isShowModal: false, // 是否显示对话框
      isShowVideo:false,
      videoTitle:"",
      videoIndex:"",
      videoSrc:"",
      colData: [
        { title: "发生时间", key: "datetime", width: "200", align: "center" },
        {
          title: "事件名称",
          key: "event_name",
          width: "auto",
          align: "center"
        },
        { title: "事件状态", key: "level", width: "100", align: "center" },
        {
          title: "事件详情",
          key: "detail",
          width: "100",
          align: "center",
          render: (h, params) => {
            return h(
              "Button",
              {
                props: {
                  type: "success",
                  size: "small"
                },
                style: {
                  marginRight: "5px"
                },
                on: {
                  click: () => {
                    this.eventDetailData = params.row;
                    this.isShowModal = true;
                  }
                }
              },
              "查看详情"
            );
          }
        }
      ]
    };
  },
  computed: {
    showTableData() {
      return this.tableData.map(ele => {
        ele.cellClassName = {
          level:
            ele.level === "合规"
              ? "demo-table-info-cell-legal"
              : "demo-table-info-cell-illegal",
          event_name:
            ele.level === "合规"
              ? "demo-table-info-cell-legal"
              : "demo-table-info-cell-illegal"
        };
        return ele;
      });
    },
    eventDetailTitle() {
      return (
        this.eventDetailData.event_name +
        " - " +
        this.eventDetailData.cause +
        " - " +
        this.eventDetailData.datetime
      );
    },
    isShowVideoPlay() {
      return this.eventDetailData.level === "合规" ? false : true;
    },
  },
  methods: {
    handleTableClick(row, index) {
      this.eventDetailData = row;
      this.isShowModal = true;
    },
    handleRowChange(currentRow, oldCurrentRow) {
      // console.log('单击行：', currentRow, oldCurrentRow)
    },
    playVideo() {
      this.isShowModal = false;
      this.videoTitle = this.eventDetailData.category+"_"+this.eventDetailData.event_name+"_"+this.eventDetailData.level+"_"+this.eventDetailData.datetime
      this.videoIndex = this.eventDetailData.index;
      this.isShowVideo = true;
    },
    cancelModal(index){
      // console.log(this.$refs["VideoMp4"+index].$refs.videoPlayer.player.pause())
      this.$refs.VideoMp4.$refs.videoPlayer.player.pause()
    }
  }
};
</script>

<style lang="less">
@table-background-color: #0a4271;

.monitor-table .ivu-table {
  color: #fff;
  font-size: 16px;
  background-color: #01237c;
  overflow-x: hidden;
  overflow-y: hidden;
}
// 表格字体
.monitor-table .ivu-table td {
  font-size: 16px;
}
// 表格头的字体
.monitor-table .ivu-table th {
  background-color: @table-background-color;
  font-size: 16px;
  height: 30px;
}
.monitor-table .ivu-table-wrapper {
  border: 1px solid @table-background-color;
  height: 100% !important;
}
.monitor-table .ivu-table:after {
  background-color: @table-background-color;
}
.monitor-table .ivu-table td,
.ivu-table th {
  border-bottom: 1px solid @table-background-color;
}
// 合规
.monitor-table .ivu-table .demo-table-info-cell-legal {
  color: #13c2c2;
  font-weight: bold;
}
// 违规
.monitor-table .ivu-table .demo-table-info-cell-illegal {
  color: #ffec3d;
  font-weight: bold;
}
.monitor-table .ivu-table-row-highlight td {
  background-color: #36cfc987 !important;
}
.demo-table-row-selected {
  background-color: #ffec3d;
}
.table-detail-xxx .ivu-icon-ios-close {
  font-size: 61px !important;
}
</style>
